<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <link rel="stylesheet" href="a.css">
</head>
<body>

    <div>开头</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhang</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>zhangd</div>
    <div>最后</div>

    <div>
        <button id="backToTop">返回顶部</button>
    </div>
<script>

    window.onscroll = function () {
        var scroollTop = document.documentElement.scrollTop
        if (scroollTop >= 500) {
            document.getElementById('backToTop').style.display = 'block';
        }
    }
    document.getElementById('backToTop').onclick = function () {
        document.documentElement.scrollTop = 0
        document.getElementById('backToTop').style.display = 'none';
    }

</script>
</body>
</html>